//
//  MyIncomeViewController.m
//  Doctors
//
//  Created by 王森 on 16/4/14.
//  Copyright © 2016年 王森. All rights reserved.
//

#import "MyIncomeViewController.h"
#import "MyIncomeHeaderView.h"
#import "MyIncomeHeadeDetailrView.h"
#import "MJRefresh.h"

@interface MyIncomeViewController ()
{
    NSDictionary *dataDic;
    
}
@end

@implementation MyIncomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self setTextTitleViewWithFrame:CGRectMake(0, 0, 60, 20) title:@"我的收入" fontSize:18];
    
      [self customTableView];
    
    self.tableview.hidden=YES;
    
    [self addLeftBackBtn:nil];
    
    
//    UINib *nib=[UIView loadNibNamed:@"MyCustomerTableViewCell" bundle:nil];
//    
//    [self.tableview registerNib:nib forCellReuseIdentifier:@"MyCustomerTableViewCell"];
    
    __weak typeof(self)weakSelf=self;
    [weakSelf requestData];
    
    self.tableview.mj_header= [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self.dataArray removeAllObjects];
        
        [weakSelf requestData];
        
    }];

    // Do any additional setup after loading the view.
}

-(void)requestData
{
    
    
    [self addProgressHUD];
    
    NSDictionary *dictionary=[NSDictionary dictionaryWithObjectsAndKeys:[self getArtisanId], @"artisanId", nil];
    
    NSLog(@"订单详情参数：%@",dictionary);
    [[WSNetworkApi shareManager]postWithUrl:@"/artisan/getIncome" parameters:dictionary option:RequestCenterCachePolicyCacheAndLocal sucess:^(id responseObject) {
        [self.tableview.mj_header endRefreshing];
        
        [self.tableview.mj_footer endRefreshing];
        
        
        [self removeStatuslable];
        
        NSLog(@"%@",responseObject);
        
        
        
        if ([responseObject[@"status"] isEqualToString:@"ok"]) {
            
            
            dataDic=responseObject[@"incomeInfo"];
            
            self.tableview.hidden=NO;

            
        }
        else{
            
            [self showFailed:responseObject[@"message"]];
            
        }
        
        [self.tableview reloadData];
        
        
    } failur:^(NSError *error) {
        
        [self removeStatuslable];
        [self.tableview.mj_header endRefreshing];
        
        
        
    }];
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 0;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 200+220;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    ALLOC(UIView , view);
    
    
    ALLOC(MyIncomeHeaderView, view1);
    [view1 fuZhi:dataDic];
    
    FRAME(view1, 0, 0, SCREEN_WIDTH, 200);
    
    
 
    ALLOC(MyIncomeHeadeDetailrView, view2);
    
    [view2 fuZhi:dataDic];

    FRAME(view2, 0, view1.bottom, SCREEN_WIDTH, 220);
    [view addSubview:view1];
    [view addSubview:view2];

    return view;
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableCell"];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TableCell"];
        //        cell.backgroundColor = [UIColor clearColor];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
